/*
 * @Author       : 邱狮杰
 * @Date         : 2021-05-19 17:15:33
 * @LastEditTime : 2021-05-19 17:28:59
 * @FilePath     : /wedding-dress-selection/src/reducer/weddingList.tsx
 * @Description  : 婚礼列表
 */

import { createContext, Dispatch, useReducer } from 'react'
export const CreateWedding = createContext({})
// 重制
export const RESET = 'reset'
interface StateConfig {
  id: number
  pic: string[] | string
  like: boolean
}
interface Action {
  type: typeof RESET
  data: StateConfig[]
}

export interface useWeddingContextType {
  weddingState: StateConfig
  weddingDispatch: Dispatch<Action>
}

function reducerWedding(state: StateConfig[], action: Action) {
  switch (action.type) {
    case RESET:
      return action.data
    default:
      return state
  }
}

export const WeddingContext = (props: any) => {
  const [weddingState, weddingDispatch] = useReducer(reducerWedding, [])
  return <CreateWedding.Provider value={{ weddingState, weddingDispatch }}>{props.children}</CreateWedding.Provider>
}
